<?php

declare(strict_types=1);
/**
 * Author: Zane
 * Email: 873934580@qq.com
 * Date: 2023/5/29.
 */

namespace App\Models;

use App\Models\Traits\ModelCache;
use App\Models\Traits\ModelField;
use Illuminate\Database\Eloquent\SoftDeletes;

class Permission extends \Spatie\Permission\Models\Permission
{
    use ModelCache;
    use ModelField;
    use SoftDeletes;

    protected $guard_name;

    public function __construct()
    {
        $this->guard_name = config('auth.app_guard_name');
        parent::__construct(['guard_name' => config('auth.app_guard_name')]);
    }

    public function getFillable(): array
    {
        if ($this->fillable) {
            return $this->fillable;
        }

        return $this->getTableFields();
    }

    public function freshTimestamp(): int
    {
        return time();
    }

    public function fromDateTime($value)
    {
        return $value;
    }

    public function getCreatedAtAttribute()
    {
        return date('Y-m-d H:i:s', $this->attributes['created_at']);
    }

    public function getUpdatedAtAttribute()
    {
        return date('Y-m-d H:i:s', $this->attributes['updated_at']);
    }
}
